from config.config import config
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class page(config):
    # 搜索框 id="chat-textarea"
    if(By.ID=='chat-textarea'):
        input_loc=(By.ID,'chat-textarea')
        def input(self):
            self.send_keys(self.input_loc,'我喜欢软件测试')
    else:
        input_loc = (By.ID, 'kw')
        def input(self):
            self.send_keys(self.input_loc,'我喜欢软件测试')

    # 搜索按钮 id="chat-submit-button" su
    if(By.ID=='chat-submit-button'):
        search_loc = (By.ID,'chat-submit-button')
        def search(self):
            self.click(self.search_loc)
    else:
        search_loc = (By.ID, 'su')
        def search(self):
            self.click(self.search_loc)

    # /html/body/div[3]/div[4]/div[1]/div[3]/div[1]/div
    get_all_loc = (By.XPATH,'/html/body/div[3]/div[4]/div[1]/div[3]')
    def get_all(self):
        return self.find_elements(self.get_all_loc)

    dy1_loc = (By.XPATH,'/html/body/div[3]/div[4]/div[1]/div[3]')
    def dy1(self):
        return self.text(self.dy1_loc)

    def luoji_01(self):
        self.open_url('https://www.baidu.com')
        self.input()
        self.search()
        time.sleep(5)
        self.get_all()
        print('--------------***--------------')
        print(self.dy1())
        assert '我喜欢软件测试' in self.dy1(), "搜索结果中未找到目标文本"
        time.sleep(5)